package pzl.com.library.data;

import android.graphics.Color;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zl.peng
 * @version [1.0, 2016-11-21]
 */
public class DataList<E extends Entry> {
    private static final String TAG = "DataList";

    protected List<E> dataList = new ArrayList<>();

    public float maxValue = -Float.MAX_VALUE;
    public float minValue = Float.MAX_VALUE;

    private int mPrimaryColor = Color.BLACK;

    public DataList() {
    }

    protected void calcMaxMinValue() {
        if (dataList == null) return;
        for (E e : dataList) {
            float v = e.valueY();
            if (v > maxValue) maxValue = v;
            if (v < minValue) minValue = v;
        }
    }

    public void add(E e) {
        dataList.add(e);
    }

    public int size() {
        return dataList.size();
    }

    public int maxIndex() {
        return dataList.size() == 0 ? 0 : dataList.size() - 1;
    }

    public Entry getEntry(int index) {
        return dataList.get(index);
    }

    public void addAll(ArrayList sub) {
        dataList.addAll(sub);
    }

    public int getPrimaryColor() {
        return mPrimaryColor;
    }

    public void setPrimaryColor(int primaryColor) {
        mPrimaryColor = primaryColor;
    }
}
